/**
 * 工具类
 */
import Vue from 'vue'
import CryptoJS from 'crypto-js'
let Base64 = require('js-base64').Base64

const AES_KEY = "E0536D6080138391"
const IV = "CF40C58AA81E22A5"
//加密
export const  encryptAes = (data)=>{
  const key = CryptoJS.enc.Utf8.parse(AES_KEY);
  const iv = CryptoJS.enc.Utf8.parse(IV);
  const encrypted = CryptoJS.AES.encrypt(data, key, {
    iv,
    mode: CryptoJS.mode.CBC,
    padding: CryptoJS.pad.Pkcs7,
  });
  //自动转为base64
  return encrypted.toString();
}

//解密
export const decryptAes = (data) =>{
  const key = CryptoJS.enc.Utf8.parse(AES_KEY);
  const iv = CryptoJS.enc.Utf8.parse(IV);
  const decrypt = CryptoJS.AES.decrypt(data, key, {
    iv,
    mode: CryptoJS.mode.CBC,
    padding: CryptoJS.pad.Pkcs7,
  }).toString(CryptoJS.enc.Utf8);
  return decrypt;
}

export const  encryptBase64 = (word) =>{
  word = Base64.encode(word);
  return word
}

export const  decryptBase64 = (word) =>{
  word = Base64.decode(word);
  return word
}
